#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
样式管理模块
"""

import os
from pathlib import Path


def load_styles():
    """加载QSS样式"""
    # 获取样式文件路径
    current_dir = Path(__file__).parent
    style_file = current_dir / "styles.qss"
    
    if style_file.exists():
        with open(style_file, 'r', encoding='utf-8') as f:
            return f.read()
    else:
        # 如果样式文件不存在，返回默认样式
        return get_default_styles()


def get_default_styles():
    """获取默认样式"""
    return """
/* 主窗口样式 */
QMainWindow {
    background-color: #f5f5f5;
    font-family: "Microsoft YaHei", "SimHei", sans-serif;
    font-size: 12px;
}

/* 区域标题样式 */
#section_title {
    font-size: 14px;
    font-weight: bold;
    color: #333333;
    padding: 5px 0px;
    border-bottom: 2px solid #0078d4;
    margin-bottom: 5px;
}

/* 路径设置框架样式 */
#path_frame {
    background-color: #ffffff;
    border: 1px solid #d1d1d1;
    border-radius: 5px;
    margin: 5px 0px;
}

/* 路径输入框样式 */
#path_input {
    padding: 8px 12px;
    border: 1px solid #d1d1d1;
    border-radius: 3px;
    background-color: #ffffff;
    font-size: 12px;
}

#path_input:focus {
    border-color: #0078d4;
    outline: none;
}

/* 日期输入框样式 */
#date_input {
    padding: 8px 12px;
    border: 1px solid #d1d1d1;
    border-radius: 3px;
    background-color: #ffffff;
    font-size: 12px;
    text-align: center;
}

#date_input:focus {
    border-color: #0078d4;
    outline: none;
}

/* 保存路径按钮样式 */
#save_path_btn {
    background-color: #0078d4;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: bold;
}

#save_path_btn:hover {
    background-color: #106ebe;
}

#save_path_btn:pressed {
    background-color: #005a9e;
}

/* 添加订单按钮样式 */
#add_order_btn {
    background-color: #107c10;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: bold;
}

#add_order_btn:hover {
    background-color: #0e6b0e;
}

#add_order_btn:pressed {
    background-color: #0c5a0c;
}

/* 状态标签样式 */
#status_label {
    color: #666666;
    font-size: 11px;
    padding: 5px 0px;
    font-style: italic;
}

/* 筛选框架样式 */
#filter_frame {
    background-color: #ffffff;
    border: 1px solid #d1d1d1;
    border-radius: 5px;
    margin: 5px 0px;
}

/* 数字标签页样式 */
#number_tab {
    background-color: #f8f9fa;
    color: #333333;
    border: 1px solid #d1d1d1;
    padding: 6px 12px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: bold;
}

#number_tab:hover {
    background-color: #e9ecef;
}

#number_tab:checked {
    background-color: #0078d4;
    color: white;
    border-color: #0078d4;
}

/* 状态标签页样式 */
#status_tab {
    background-color: #f8f9fa;
    color: #333333;
    border: 1px solid #d1d1d1;
    padding: 6px 12px;
    border-radius: 3px;
    font-size: 12px;
}

#status_tab:hover {
    background-color: #e9ecef;
}

#status_tab:checked {
    background-color: #28a745;
    color: white;
    border-color: #28a745;
}

/* 筛选标签样式 */
#filter_label {
    color: #333333;
    font-size: 12px;
    font-weight: bold;
    padding: 0px 5px;
}

/* 客户下拉框样式 */
#customer_combo {
    padding: 6px 12px;
    border: 1px solid #d1d1d1;
    border-radius: 3px;
    background-color: #ffffff;
    font-size: 12px;
    min-width: 120px;
}

#customer_combo:focus {
    border-color: #0078d4;
    outline: none;
}

/* 确认按钮样式 */
#confirm_btn {
    background-color: #28a745;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 3px;
    font-size: 12px;
}

#confirm_btn:hover {
    background-color: #218838;
}

#confirm_btn:pressed {
    background-color: #1e7e34;
}

/* 取消按钮样式 */
#cancel_btn {
    background-color: #6c757d;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 3px;
    font-size: 12px;
}

#cancel_btn:hover {
    background-color: #5a6268;
}

#cancel_btn:pressed {
    background-color: #545b62;
}

/* 清除筛选按钮样式 */
#clear_filter_btn {
    background-color: #dc3545;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 3px;
    font-size: 12px;
}

#clear_filter_btn:hover {
    background-color: #c82333;
}

#clear_filter_btn:pressed {
    background-color: #bd2130;
}

/* 实时推送按钮样式 */
#realtime_btn {
    background-color: #17a2b8;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 3px;
    font-size: 12px;
}

#realtime_btn:hover {
    background-color: #138496;
}

#realtime_btn:pressed {
    background-color: #117a8b;
}

/* 筛选说明按钮样式 */
#description_btn {
    background-color: #6f42c1;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 3px;
    font-size: 12px;
}

#description_btn:hover {
    background-color: #5a32a3;
}

#description_btn:pressed {
    background-color: #4c2d85;
}

/* 订单表格样式 */
#order_table {
    background-color: #ffffff;
    border: 1px solid #d1d1d1;
    border-radius: 5px;
    gridline-color: #e0e0e0;
    selection-background-color: #e3f2fd;
    font-size: 12px;
}

#order_table::item {
    padding: 8px;
    border-bottom: 1px solid #f0f0f0;
}

#order_table::item:selected {
    background-color: #e3f2fd;
    color: #1976d2;
}

/* 表格头部样式 */
#order_table QHeaderView::section {
    background-color: #f8f9fa;
    color: #333333;
    padding: 10px 8px;
    border: 1px solid #e0e0e0;
    border-left: none;
    font-weight: bold;
    font-size: 12px;
}

#order_table QHeaderView::section:first {
    border-left: 1px solid #e0e0e0;
}

#order_table QHeaderView::section:hover {
    background-color: #e9ecef;
}

/* 状态按钮样式 */
#not_engraved_btn {
    background-color: #0078d4;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: bold;
}

#not_engraved_btn:hover {
    background-color: #106ebe;
}

#not_confirmed_btn {
    background-color: #28a745;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: bold;
}

#not_confirmed_btn:hover {
    background-color: #218838;
}

#pending_btn {
    background-color: #ffc107;
    color: #212529;
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: bold;
}

#pending_btn:hover {
    background-color: #e0a800;
}

#done_btn {
    background-color: #17a2b8;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: bold;
}

#done_btn:hover {
    background-color: #138496;
}

/* 复选框样式 */
QCheckBox {
    spacing: 5px;
}

QCheckBox::indicator {
    width: 16px;
    height: 16px;
    border: 1px solid #d1d1d1;
    border-radius: 3px;
    background-color: #ffffff;
}

QCheckBox::indicator:checked {
    background-color: #0078d4;
    border-color: #0078d4;
    image: url();
}

QCheckBox::indicator:hover {
    border-color: #0078d4;
}

/* 滚动条样式 */
QScrollBar:vertical {
    background-color: #f1f1f1;
    width: 12px;
    border-radius: 6px;
}

QScrollBar::handle:vertical {
    background-color: #c1c1c1;
    border-radius: 6px;
    min-height: 20px;
}

QScrollBar::handle:vertical:hover {
    background-color: #a8a8a8;
}

QScrollBar::add-line:vertical,
QScrollBar::sub-line:vertical {
    height: 0px;
}

QScrollBar:horizontal {
    background-color: #f1f1f1;
    height: 12px;
    border-radius: 6px;
}

QScrollBar::handle:horizontal {
    background-color: #c1c1c1;
    border-radius: 6px;
    min-width: 20px;
}

QScrollBar::handle:horizontal:hover {
    background-color: #a8a8a8;
}

QScrollBar::add-line:horizontal,
QScrollBar::sub-line:horizontal {
    width: 0px;
}
"""
